package br.com.comdoc.repositorio;

//@author Keanujorge
import br.com.comdoc.DAO.LinkDB;
import br.com.comdoc.entidade.Contato;
import br.com.comdoc.entidade.Empresa;
import br.com.comdoc.entidade.Endereco;
import br.com.comdoc.interfaces.InterfaceEmpresa;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JOptionPane;

public class RepositorioEmpresa implements InterfaceEmpresa {

    private Connection conn;
    private String query;
    private PreparedStatement stmt;
    private ResultSet rs;

    @Override
    public void salvar(int idEndereco, int idContato, String razaoSocial, String nomeFantazia, 
    String CNPJ, String IE, int situacao) {     
        
        Empresa empresa = new Empresa(idEndereco, idContato, razaoSocial, nomeFantazia, 
                CNPJ, IE, situacao);
        Endereco endereco = new Endereco();
        endereco.setId(idEndereco);
        Contato contato = new Contato();
        contato.setId(idContato);
        
        try {
            conn = LinkDB.getConnection();
            query = "INSERT INTO empresa(empresa.CNPJEMPRESA, empresa.IDENDERECO, "
                    + "empresa.IDCONTATO, empresa.IEEMPRESA, empresa.RAZAOSOCIAL, "
                    + "empresa.NOMEFANTAZIA, empresa.SITUACAOEMPRESA) VALUES(?, ?, ?, ?, ?, ?, ?)";
            stmt = conn.prepareStatement(query);
            stmt.setString(1, empresa.getCNPJ());
            stmt.setInt(2, endereco.getId());
            stmt.setInt(3, contato.getId());
            stmt.setString(4, empresa.getIE());
            stmt.setString(5, empresa.getRazaoSocial());
            stmt.setString(6, empresa.getNomeFantazia());
            stmt.setInt(7, empresa.getSituacao());
            stmt.executeUpdate();
            
            JOptionPane.showMessageDialog(null, "Salvo com sucesso.");
            
            stmt.close();
            conn.close();
        } catch (ClassNotFoundException | SQLException ex) {
            JOptionPane.showMessageDialog(null, "Erro:\n" + ex);
        }

    }

    @Override
    public void alterar(int idEndereco, int idContato, String razaoSocial, String nomeFantazia,
            String CNPJ, String IE, int situacao) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void excluir(String cnpj) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ArrayList pegarTodos() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ArrayList consultarPorCNPJ(String CNPJ) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ArrayList consultarPorRazaoSocial(String razaoSocial) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ArrayList consultarPorNomeFantazia(String nomeFantazia) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
